//Credits to Scott Olson, see: http://www.gscottolson.com/blackbirdjs/
namespace("controls.Logger", {
	'@inherits'    : w3c.HtmlComponent,
	'@description' : "Ported from the original 'BlackBird' logger by G. Scott Olson",
	"@stylesheets" : "css/Logger.css",
	'@signature'   : {'@author' : "jaysmith024@gmail.com"},
	
	
	initialize : function(){
		this.setEnabled(config.debug);
		this.addEventDelegate(".button-close:click", this.onclose.bind(this));
		this.addEventDelegate(".button-clear:click", this.onclear.bind(this));
		(this.isEnabled()) ? this.show() : null;
	},
	
	dragstart : function(e){
		this.canDrag = this.hasClass("handle",e.dragEvent.target);
		this.setStyles({"z-index":application.absoluteZindex()})
		return this.canDrag;
	},
	
	drag : function(){
		return this.canDrag;
	},
	
	dragend : function(){
		this.info("Logger dropped");
	},
	
	setTitle : function(str){
		var titlebar = this.querySelector(".titlebar");
			titlebar.innerHTML = str;
	},
	
	innerHTML:
	'<div style="-webkit-user-select:none;-moz-user-select:none;position:absolute;" class="bbSmall bbTopRight">\
		<div class="header">\
			<div class="titlebar handle" style="background:transparent;"><b>UI Analytics</b></div>\
			<div class="left handle">\
				<div title="click to filter by message type" class="filters" id="bbFilters">\
				</div>\
			</div>\
			<div class="right handle">\
				<div class="controls" id="bbControls">\
					<span op="clear" title="clear" class="button-clear"></span>\
					<span op="close" title="close" class="button-close"></span>\
				</div>\
			</div>\
		</div>\
		<div class="main">\
			<div class="left handle">\
				<!-- content here -->\
			</div>\
			<div class="mainBody">\
				<ol class="content-pane handle"></ol>\
			</div>\
			<div class="right handle"></div>\
		</div>\
		<div class="footer handle">\
			<div class="left handle">\
				<!-- content here -->\
			</div>\
			<div class="right handle"></div>\
		</div>\
	</div>',
	
	isEnabled : function(){ return (config.debug && this.get("enabled")) },
	
	setEnabled : function(bool){
		if (typeof bool !== "boolean") {
			throw new TypeError("Logger#setEnabled(boolean) expects a boolean");
		}
	 	config.debug = bool;
		this.set("enabled",bool);
	},
	 
	onclose : function(e){
		this.setStyles({display:"none"});
	},
	
	getContentPane : function() {
		var pane = this.querySelector(".content-pane");
		return pane;
	},
	
	show : function(){ this.setStyles({display:"block"}) },
	
	hide : function(){ this.setStyles({display:"none"}) },
	
	info : function(msg){
		if(!this.isEnabled()) {return msg;}
		var pane = this.getContentPane();
		var el = ('<li class="info"><span class="icon"></span>' + msg + '</li>').toHtmlElement();
		pane.appendChild(el);
	},
	
	warn : function(msg){
		if(!this.isEnabled()) {return msg;}
		var pane = this.getContentPane();
		var el = ('<li class="warn"><span class="icon"></span>' + msg + '</li>').toHtmlElement();
		pane.appendChild(el);
	},
	
	error : function(msg){
		if(!this.isEnabled()) {return msg;}
		var pane = this.getContentPane();
		var el = ('<li class="error"><span class="icon"></span>' + msg + '</li>').toHtmlElement();
		pane.appendChild(el);
	},
	
	onclear : function(){
		var pane = this.getContentPane();
			pane.innerHTML = "";
	}
});